/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package action.news;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import java.util.Locale;
import javax.servlet.http.HttpServletRequest;
import org.apache.struts2.interceptor.ServletRequestAware;
import org.springframework.context.support.ResourceBundleMessageSource;
import po.User;
import service.NewsService;
import service.OrgService;

/**
 *
 * @author sony
 */
public class DeleteNewsAction extends ActionSupport implements ServletRequestAware {

    private HttpServletRequest request;
    private NewsService newsService;
    private String message;
    private ResourceBundleMessageSource messageSource;

    public String execute() {
        if (ActionContext.getContext().getSession().get("user") == null) {
            message = messageSource.getMessage("authError", null, Locale.CHINA);
            return ERROR;
        } else {
            int userId = ((User) ActionContext.getContext().getSession().get("user")).getId();
            int newsId = Integer.parseInt(request.getParameter("id"));
            if(!newsService.isAuthor(newsId, userId)&&((User) ActionContext.getContext().getSession().get("user")).getType()!=1){
                message = messageSource.getMessage("authError", null, Locale.CHINA);
                return ERROR;
            }else{
                newsService.deleteNews(newsId);
            }
        }

        return SUCCESS;
    }

    public void setServletRequest(HttpServletRequest request) {
        this.request = request;
    }

    public NewsService getNewsService() {
        return newsService;
    }

    public void setNewsService(NewsService newsService) {
        this.newsService = newsService;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public ResourceBundleMessageSource getMessageSource() {
        return messageSource;
    }

    public void setMessageSource(ResourceBundleMessageSource messageSource) {
        this.messageSource = messageSource;
    }

}
